package com.rainman.simpleredis.demo.process_flow_worker;

import com.rainman.simpleredis.core.SimpleRedis;
import com.rainman.simpleredis.core.process_flow.SimpleProcessFlowWorkerInterface;
import com.rainman.simpleredis.core.process_flow.ProcessWorkerReturn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * 流式任务执行者
 * 本系统订单
 *
 */
@Component
public class LocalOrderOpenWorker implements SimpleProcessFlowWorkerInterface {

    @Autowired
    SimpleRedis simpleRedis;

    @Override
    public ProcessWorkerReturn doWork(List<String> params) {

        System.out.println("********本地订单系统下单*******"+new Date());

        System.out.println("收到参数"+params.get(0));

        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


        ProcessWorkerReturn dealSuc = new ProcessWorkerReturn(ProcessWorkerReturn.StateSuc
                ,simpleRedis.uniqueIdGetOne()+"");//返回结果,这里返回订单号

        System.out.println("********本地订单系统下单完成*******"+new Date());
        return dealSuc;
    }

    @Override
    public ProcessWorkerReturn unDoWork(List<String> params, String returnInfo) {
        System.out.println("********本地订单系统回滚*******"+new Date());

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("********本地订单系统回滚完成*******"+new Date());

        return new ProcessWorkerReturn(ProcessWorkerReturn.StateSuc);
    }

    @Override
    public String workType() {
        return "本系统订单";
    }
}
